package com.zqs.service.impl;

import com.zqs.entity.Brand;
import com.zqs.entity.BrandCategory;
import com.zqs.entity.Category;
import com.zqs.mapper.BrandCategoryMapper;
import com.zqs.mapper.BrandMapper;
import com.zqs.mapper.CategoryMapper;
import com.zqs.service.BrandService;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class BrandServiceImpl implements BrandService {

    @Autowired
    private BrandMapper brandMapper;

    @Autowired
    private BrandCategoryMapper brandCategoryMapper;

    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public List<Brand> showCarList() {
        List<Brand> brandList = brandMapper.selectAll();

        for (Brand b :brandList) {
            ArrayList<Category> list = new ArrayList<>();
            List<BrandCategory> byBid = brandCategoryMapper.getByBid(b.getBid());
            for (BrandCategory bc :byBid) {
                Category category = categoryMapper.findByCid(bc.getCid());
                list.add(category);
            }
            b.setCategory(list);
        }
        return brandList;
    }

}
